﻿#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
using namespace std;
#include<string>

void test1()
{
	string s1;//调用无参的构造函数，构造空的string类对象
	string s2("hello RoundBottle");//用常量字符串构造string类对象
	string s3(13, 'x');//用 13个x 构造 string类对象
	string s4(s2);//拷贝构造

	//cout << s1.size() << endl;
	//cout << s1.capacity() << endl;
	/*cout << sizeof(s1) << endl;*/
	//cout << endl;

	/*cout << s2.size() << endl;
	cout << s2.capacity() << endl;
	cout << endl;

	cout << s3.size() << endl;
	cout << s3.capacity() << endl;
	cout << endl;

	cout << s4.size() << endl;
	cout << s4.capacity() << endl;
	cout << endl;*/

	s1 += "xxxxxxxxxxxxxxxxxxx";
	cout << s1.size() << endl;
	cout << s1.capacity() << endl;
	cout << endl;

	s1 += "xxxxxxxxxxxxxxxxxxx";
	cout << s1.size() << endl;
	cout << s1.capacity() << endl;
	cout << endl;


	s1 += "xxxxxxxxxxxxxxxxxxx";
	cout << s1.size() << endl;
	cout << s1.capacity() << endl;
	cout << endl;


	s1 += "xxxxxxxxxxxxxxxxxxx";
	cout << s1.size() << endl;
	cout << s1.capacity() << endl;
	cout << endl;
}

void test2()
{
	string s1;
	s1.push_back('H');
	s1.push_back('e');
	s1.push_back('l');
	s1.push_back('l');
	s1.push_back('o');
	s1.push_back(',');

	s1.append("RoundBottle!");
	cout << s1 << endl;


	string s2;
	s2 += "fantasy_RoundBottle";
	cout << s2 << endl;
}

void test3()
{
	string s1("RoundBottle");

	s1 += '\0';
	s1 += '!';

	cout << s1 << endl;
	cout << s1.c_str() << endl;
	cout << (void*)s1.c_str() << endl;

}

void test4()
{
	string s;
	cout << s.capacity() << " " << s.size() << endl;
	s.reserve(100);

	cout << s.capacity() << " " << s.size() << endl;

	/*s.resize(100,'x');
	cout << s.capacity() << " " << s.size() << endl;
	cout << s << endl;*/


}


void test5()
{
	string s("RoundBottle");

	cout << s << endl;
	cout << "size:" << s.size() << endl;
	cout << "capacity:" << s.capacity() << endl;
	cout << endl;

	s.resize(7);
	cout << s << endl;
	cout << "size:" << s.size() << endl;
	cout << "capacity:" << s.capacity() << endl;
	cout << endl;

	s.resize(31, 'x');
	cout << s << endl;
	cout << "size:" << s.size() << endl;
	cout << "capacity:" << s.capacity() << endl;
	cout << endl;

	s.resize(41);
	cout << s << endl;
	cout << "size:" << s.size() << endl;
	cout << "capacity:" << s.capacity() << endl;
	cout << endl;



}

void test6()
{
	string s("RoundBottle");
	s.clear();
	cout << s << endl;
	cout << "size:" << s.size() << endl;
	cout << "capacity:" << s.capacity() << endl;
	cout << endl;
}

void test7()
{
	string s("abcdefg");

	string::iterator it = s.begin();
	while (it != s.end())
	{
		cout << *it << " ";
		++it;
	}
	cout << endl;


	for (auto ch : s)
	{
		cout << ch << ' ';
	}
	cout << endl;

}



//int main()
//{
//	test7();
//
//	return 0;
//}


